#include "stdafx.h"
#include "sceneanimator.h"
#include "model/mage.h"
#include "model/potion.h"
#include "model/spell.h"
#include "scene.h"

#include "external/external.h"

SceneAnimator::SceneAnimator(Scene *scene)
    :_scene(scene)
{
}

SceneAnimator::~SceneAnimator()
{
}

void SceneAnimator::visit(Mage *mage)
{
    mage->move(mage->speedX(), mage->speedY());
    float rad = mage->radius();
    float x = mage->x();
    float y = mage->y();

    if (x - rad < 0)
        mage->move(rad - x, 0);
    else if (x + rad > _scene->width())
        mage->move(_scene->width() - x - rad, 0);

    if (y - rad < 0)
        mage->move(0, rad - y);
    else if (y + rad > _scene->height())
        mage->move(0, _scene->height() - y - rad);
}

void SceneAnimator::visit(Potion */*potion*/)
{
}

void SceneAnimator::visit(Spell *spell)
{
    spell->move(spell->speedX(), spell->speedY());
    float rad = spell->radius();
    float x = spell->x();
    float y = spell->y();

    if ((x - rad < 0)
        || (y - rad < 0)
        || (x + rad > _scene->width())
        || (y + rad > _scene->height()))
    {
        _scene->deleteObject(spell);
    }
}
